<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>封装</title>
</head>
<body>
    <h1 class="mytitle">按下F12打开控制台查看</h1>
<script>
    function inArr(a,b){
        this.a = a;
        this.b = b;
    }
    inArr.prototype.judge = function(){
        var istrue = false;
        for(var i in this.b){
            if(this.b[i] == this.a){
                istrue = true;
            }
        }
        if(istrue){
            console.log("a在b中的下标是:"+i);
        }
        else{
            console.log('-1');
        }
    }
    var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    var obj1 = new inArr(9,arr);
    obj1.judge();
    var obj2 = new inArr(99,arr);
    obj2.judge();
</script>  
</body>
</html>